<?php

require "../classes/ContactPark.class.php";
require "../classes/ParkDAO.class.php";
require "../classes/ConnectionFactory.class.php";
require "checksDate.action.php";

$park=new ContactPark();
$date=new checksDate();
$cf = new ConnectionFactory();
$db = $cf->getConnection();
$dao = new ParkDAO($db);


$park->setidClients($_POST['idcli']);
$park->setidCar($_POST['idcar']);
$park->setDatein($date->convertsDatehora($_POST['newParkDateIn']));
$park->setDateout($date->convertsDatehora($_POST['newParkDateout']));
$park->setSatatus(0);

$tarifa=$_POST['fares'];
$park->setFare($tarifa);


$park->setTotal(0);
$id = $park->getId();

    
    if (empty($id)) {
        
        
    $result = $dao->create($park);
} else {
    $dao->update($park);
}
    
    
                       
?>


<script>
        <meta http-equiv="content-type" content="text/html;charset=utf-8" />;
    var cadTest = <?php echo $result; ?>;
           
    if(cadTest){
        alert("Cadastro Efetuado Com Sucesso!");
        setTimeout("document.location = '../index.php'",500);
       
    }else{
       
        alert("Não Foi Possível Realizar o Cadastro!");
        setTimeout("document.location = '../index.php'",500);
    }
    
             
</script>
